import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.geom.RoundRectangle2D;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;

import jxl.read.biff.BiffException;

import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;
import org.joda.time.DateTime;


//@author A0097543W
@SuppressWarnings("serial")
public class GUI extends JFrame{

	private final static String newline = "\n";
	private final static String space = " ";
	private final static String endwrap = "                                          ";
	private final static String STATUS_SEARCH = "Search results";
	private final static String INVALID_CMD = "Invalid command";
	
	private final static int DISPLAY_LENGTH = 50;
	private final static int WRAP_LENGTH = 45;
	private final static int extend = 70;
	
	// display types displayArea
	private final static int COMPLETED = 0;
	private final static int INCOMPLETED = 1;
	private final static int SEARCHRESULTS = 2;
	private final static int CHANGES = 3;
	private final static int EVERYTHING = 4;
	
	// task classification
	private final static int URGENT = 1;
	private final static int CHANGED = 2;
	
	private final static DateTime FLOATING_DEADLINE	 = new DateTime(9999,12,31,23,59,0,0);
	
	// components involved
	private SchedulerLogic logic = new SchedulerLogic();  ;
	private static GUI gui = new GUI();
	
	private Vector<Integer> taskLineNum = new Vector<Integer>();
	private Vector<Integer> urgentTask = new Vector<Integer>();
	private Vector<String> commandHistory = new Vector<String>();
	private int currentView = INCOMPLETED; //default currentview as Pending tasks
	
	private TriggerOnEnter triggerOnEnter;
	private TriggerOnKeyPress triggerOnKeyPress;
	private GlobalKeyPress globalKeyPress;
	private CommandAssist commandAssist;
	
	private Highlighter.HighlightPainter painter;
	
	// fonts in Scheduler
	Font bodyFont = new Font("Courier New", Font.PLAIN, 12);
	Font headingFont = new Font("Calibri", Font.BOLD, 22);
	Font eheadingFont = new Font("Calibri", Font.BOLD, 24);
	Font ebodyFont = new Font("Courier New", Font.BOLD, 14);

	// GUI components
	JPanel mainPane = new JPanel();
	static JTextField cmdField;
	static JTextField headingField;
	static JTextField statusField;
	static JTextArea displayArea;
	static JTextArea dateField;

	// enlarge GUI components
	JFrame enlargedFrame = new JFrame();
	JTextArea textArea = new JTextArea();
	JTextField eHeading = new JTextField();
	JScrollPane eTextScroll = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
	
	// command history in cmdField
	int cmdHistPointer = 0;
	int cmdHistMax = 0;
	
	public GUI() {

		super("Scheduler");
		
		triggerOnEnter = new TriggerOnEnter();
		triggerOnKeyPress = new TriggerOnKeyPress();
		globalKeyPress = new GlobalKeyPress(true);
		commandAssist = new CommandAssist();
		
		addWindowListener(globalKeyPress);
		
		setContentPane(mainPane);
		mainPane.setBackground(new Color(100,150,210, 255));
		mainPane.setLayout(null);

		cmdField = new JTextField(20); 

		cmdField.setForeground(Color.BLACK);
		cmdField.setBounds(12, 234, 664 + extend, 26);
		cmdField.setBorder(null);
		cmdField.getDocument().addDocumentListener(commandAssist);
		cmdField.setBorder(null);

		statusField = new JTextField(20);
		statusField.setBounds(10, 259, 664 + extend, 26);
		statusField.setBorder(null);
		statusField.setBackground(new Color(100,150,210, 255));
		statusField.setFont(bodyFont);
		statusField.setForeground(Color.WHITE);
		statusField.setEditable(false);

		headingField = new JTextField("All Tasks");
		headingField.setBorder(null);
		headingField.setBounds(10, 11, 664 + extend, 26);
		headingField.setBackground(new Color(100,150,210,255));
		headingField.setFont(headingFont);
		headingField.setForeground(Color.WHITE);
		headingField.setEditable(false);

		displayArea = new JTextArea(10, 20);
		displayArea.setBounds(40, 47, 664 + extend, 194);
		displayArea.setBackground(new Color(140,180,255, 255));
		displayArea.setFont(bodyFont);
		displayArea.setForeground(Color.BLACK);
		displayArea.setEditable(false);

		JScrollPane bodyScrollPane = new JScrollPane(displayArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		bodyScrollPane.setBorder(null);
		bodyScrollPane.setBounds(12, 47, 664 + extend, 179);


		mainPane.add(cmdField);
		mainPane.add(statusField);
		mainPane.add(headingField);
		mainPane.add(bodyScrollPane);
		
		cmdField.addActionListener(triggerOnEnter);
		headingField.addKeyListener(triggerOnKeyPress);
		cmdField.addKeyListener(triggerOnKeyPress);   
	}
	
	public static void main(String[] args) throws BiffException, IOException {
		SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
	}
	
	public static void createAndShowGUI() {

		//Create and set up the window.
		gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		gui.setAlwaysOnTop(true);
		gui.setUndecorated(true);
		gui.setShape(new RoundRectangle2D.Double(0,0,690 + extend,290,15,15));
		gui.setSize(700 + extend,334);
		positionGUI(gui);
		gui.setVisible(true);

		// gui starts up and shows Pending tasks
		gui.display(INCOMPLETED);
		
		try {
			// sets the display to the top of the list
			displayArea.setCaretPosition(displayArea.getLineStartOffset(0));
		} catch (BadLocationException e) {}
	}


	// this method set the position of the GUI at the bottom right of any screen
	private static void positionGUI(Component gui) {
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
        Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
        int x = (int) rect.getMaxX() - gui.getWidth();
        int y = (int) rect.getMaxY() - gui.getHeight();
        gui.setLocation(x, y);
	}

	// this method shows the tasks in the vector being passed in onto the displayArea
	public void displayList(Vector <Task> tasks) {
		taskLineNum.clear();
		int taskNum;
		int point;
		int start;
		String taskString = "";
		String eDate = "";
		String eTime = "";
		String sDateTime= "";
		String sDate = "";
		String sTime = "";
		String tTaskTime="";
		String sDay;
		String eDay;
		boolean isTimed = false;
		ArrayList<String> wrappedText = new ArrayList<String>();
		
		urgentTask.clear();
		displayArea.setText("");
		textArea.setText("");
		
		for (int i=0; i<tasks.size();i++) {
			wrappedText.clear();
			String dateTime;
			if (tasks.get(i).getEndDateTime().isEqual(FLOATING_DEADLINE)) {
				sDate = "";
				dateTime = "";
			}
			else {
				// formats the date time of the tasks to be display
				eDate = tasks.get(i).getDay()+ "/" + tasks.get(i).getMonth() + "/" +
						tasks.get(i).getYear();
				eTime = tasks.get(i).getHour() + ":" + tasks.get(i).getMinute();
				dateTime = eDate + "   " + eTime;

				sDate =tasks.get(i).getSDay()+ "/" + tasks.get(i).getSMonth() + "/" +
						tasks.get(i).getSYear();
				sTime = tasks.get(i).getSHour() + ":" + tasks.get(i).getSMinute();
				sDateTime = sDate + "   " + sTime;

				// check that the task is a timed task
				if (!sDateTime.equals(dateTime)) {
					isTimed = true;

					sDay = tasks.get(i).sDayOfWeek();
					eDay = tasks.get(i).eDayOfWeek();
					// check if timed task is within the same date
					if (sDate.equals(eDate) && sDay.equals(eDay)) {
						tTaskTime = sDate + " " + sDay + " "  + sTime + " ~ " + eTime;
					} else {
						tTaskTime = sDate + " " + sDay + " " + sTime + " ~ " + eDate + " " + eDay + " " + eTime;
					}
				}
				dateTime = "   " + eDate + " " + tasks.get(i).sDayOfWeek() + " " + eTime;
				
			}
			
			
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
			Calendar cal = Calendar.getInstance();
			String today = dateFormat.format(cal.getTime());
			
			// checks if task is urgent
			if (today.equals(sDate)) {
				urgentTask.add(i);
			}
			
			String descrip = tasks.get(i).getDescription();
			wrappedText.addAll(performWrap(descrip));
			
			taskNum = i + 1;
			// align the information
			taskString = fillSpace(isTimed, wrappedText.get(0), dateTime, tTaskTime, i);
			
			displayArea.append((taskNum) + ". " + taskString + newline);
			textArea.append((taskNum) + ". " + taskString + newline);
			taskLineNum.add(taskNum);
			
			
			if (wrappedText.size() > 1) {
				for(int j = 1; j < wrappedText.size(); j++) {
					displayArea.append(space + space + space + wrappedText.get(j) + newline);
					textArea.append(space + space + space + wrappedText.get(j) + newline);
					taskLineNum.add(taskNum);
				}
			}
			displayArea.append(newline);
			textArea.append(newline);
			taskLineNum.add(0);
			isTimed = false;
		}
		try {
			point = logic.getDisplayIndex(CHANGES).get(0) + 1;
			start = taskLineNum.indexOf(point);

			//setting of the line position of the displayArea after action
			displayArea.setCaretPosition(textArea.getDocument().getDefaultRootElement().getElement(start).getStartOffset());  

		} catch (Exception ex) {
			System.out.println("no changes");
		}
	}

	// wrap text if the tasks decription is too long
	private ArrayList<String> performWrap(String descrip) {
		ArrayList<String> wrappedText = new ArrayList<String>();
		if (descrip.length() < WRAP_LENGTH){
			wrappedText.add(descrip);
		} else {
			int notFirstLine = 0;
			while( descrip.length() > WRAP_LENGTH) {
				if(notFirstLine == 0) {
					wrappedText.add(descrip.substring(0, WRAP_LENGTH));
					notFirstLine++;
				} else {
					wrappedText.add(descrip.substring(0, WRAP_LENGTH) + endwrap + endwrap);
				}
				descrip = descrip.substring( WRAP_LENGTH);
			}
			wrappedText.add(descrip + endwrap + endwrap);
		}
		return wrappedText;
	}

	// this method aligns the information, decription, date, time
	private String fillSpace(boolean isTimed, String descrip, String dateTime, String tTaskTime, int index) {
		int stringLength = descrip.length();
		for(int j = 0; j < (DISPLAY_LENGTH - stringLength); j++) {
			descrip = descrip + space;
		}
		descrip = removeLastSpace(index, descrip);
		if(isTimed == false) {
			descrip = descrip + dateTime + endwrap + endwrap;
		} else {
			descrip = descrip + "   " + tTaskTime + endwrap + endwrap;
		}
		return descrip;
	}

	public String removeLastSpace(int index, String descrip) {
		if(index >= 9) {
			descrip = descrip.substring(0, descrip.length()-1);
		}
		return descrip;
	}


	public void display(int displayType) {
		Vector<Task> tasks = logic.getTaskList();
		urgentTask.clear();
		textArea.setText("");
		cmdField.setText("");

		if(displayType == EVERYTHING) {
			headingField.setText("All Tasks");
			displayList(tasks);
			eHeading.setText("All Tasks");
			checkUrgent();
		} else if ( displayType ==  INCOMPLETED) {
			headingField.setText("Pending Tasks");
			toDisplay(tasks, logic.getDisplayIndex(INCOMPLETED));
			eHeading.setText("Pending Tasks");
			checkUrgent();
		} else if ( displayType ==  COMPLETED) {
			headingField.setText("Completed Tasks");
			toDisplay(tasks, logic.getDisplayIndex(COMPLETED));
			eHeading.setText("Completed Tasks");
		}else if ( displayType ==  SEARCHRESULTS) {
			headingField.setText("Search Results");
			toDisplay(tasks, logic.getDisplayIndex(SEARCHRESULTS));
			eHeading.setText("Search Results");
			checkUrgent();
		}

	}

	// checks for urgent tasks, i.e. tasks that are due today
	private void checkUrgent() {
		for(int i = 0; i < urgentTask.size(); i++) {
			highlightTask(urgentTask.get(i) + 1, URGENT);
		}
	}
	
	// global hotkeys for the GUI
	private class GlobalKeyPress implements WindowListener, NativeKeyListener{

		Boolean isVisible = false;
		
		GlobalKeyPress(Boolean visible) {
			isVisible = visible;
		}
		
		@Override
		public void windowOpened(WindowEvent e) {
			//Initialise native hook.
            try {
                    GlobalScreen.registerNativeHook();
            }
            catch (NativeHookException ex) {
                    System.err.println("There was a problem registering the native hook.");
                    System.err.println(ex.getMessage());
                    System.exit(1);
            }

            GlobalScreen.getInstance().addNativeKeyListener(this);
		}
		
		@Override
		public void windowClosed(WindowEvent e) {
            //Clean up the native hook.
            GlobalScreen.unregisterNativeHook();
            System.runFinalization();
            System.exit(0);
		}
		
		@Override
		public void windowActivated(WindowEvent e) {}
		@Override
		public void windowClosing(WindowEvent e) {}
		@Override
		public void windowDeactivated(WindowEvent e) {}
		@Override
		public void windowDeiconified(WindowEvent e) {}
		@Override
		public void windowIconified(WindowEvent e) {}

		@Override
		public void nativeKeyPressed(NativeKeyEvent e) {
			int keyCode = e.getKeyCode();
			if ( keyCode == NativeKeyEvent.VK_F8) {						// hotkey to hide unhide Scheduler
				SwingUtilities.invokeLater(new Runnable() {
					public void run() {
						//this will run on Swing's Event Dispatch Thread
						if (isVisible == true) {
							cmdField.requestFocus();
							GUI.this.setVisible(false);
							isVisible = false;
						}
						else {
							GUI.this.setVisible(true);
							isVisible = true;
						}
					}
				});
			}
		}

		@Override
		public void nativeKeyReleased(NativeKeyEvent e) {
		}

		@Override
		public void nativeKeyTyped(NativeKeyEvent arg0) {}


	}
	
	private class TriggerOnEnter implements ActionListener{
		public void actionPerformed(ActionEvent arg0) {
			String status = "";
			String text = cmdField.getText();
			Vector<Integer> taskToShow = new Vector<Integer>();
			
			commandHistory.add(text);
			cmdHistPointer = commandHistory.size() -1;
			try {
			Command userCommand = new Command(text);
			status = logic.executeCommand(userCommand);
			} catch (NullPointerException e) {
				status = INVALID_CMD;
			}
			
			urgentTask.clear();
			if(status.equals(STATUS_SEARCH)) {
				statusField.setText("");
				headingField.setText(status);
				currentView = SEARCHRESULTS;
				taskToShow = logic.getDisplayIndex(SEARCHRESULTS);
				Vector<Task> tasks = logic.getTaskList();
				toDisplay(tasks, taskToShow);
			} else {
				statusField.setText(status);
				display(EVERYTHING);
				currentView = EVERYTHING;
			}
			
			Vector<Integer> changes = logic.getDisplayIndex(CHANGES);
			highlightChanges(changes);
		}
		
	}
	

	public void toDisplay(Vector<Task> tasks, Vector<Integer> taskToShow) {
		taskLineNum.clear();
		int taskNum;
		int newUrgent = 0;
		String eDate = "";
		String eTime = "";
		String taskString = "";
		String sDateTime = "";
		String sDate = "";
		String sTime = "";
		String tTaskTime= "";
		String sDay;
		String eDay;
		ArrayList<String> wrappedText = new ArrayList<String>();
		urgentTask.clear();
		boolean isTimed = false;
		
		displayArea.setText("");
		textArea.setText("");
		for (int i=0; i<tasks.size();i++) {
			if(!taskToShow.contains(i)) {
				continue;
			}
			wrappedText.clear();
			String dateTime;
			if (tasks.get(i).getEndDateTime().isEqual(FLOATING_DEADLINE)) {
				sDate = "";
				dateTime = "";
			}
			else {
				// formats the date time of the tasks to be display
				eDate = tasks.get(i).getDay()+ "/" + tasks.get(i).getMonth() + "/" +
						tasks.get(i).getYear();
				eTime = tasks.get(i).getHour() + ":" + tasks.get(i).getMinute();
				dateTime = eDate + "   " + eTime;

				sDate =tasks.get(i).getSDay()+ "/" + tasks.get(i).getSMonth() + "/" +
						tasks.get(i).getSYear();
				sTime = tasks.get(i).getSHour() + ":" + tasks.get(i).getSMinute();
				sDateTime = sDate + "   " + sTime;
				
				// check that the task is a timed task
				if (!sDateTime.equals(dateTime)) {
					isTimed = true;
					sDay = tasks.get(i).sDayOfWeek();
					eDay = tasks.get(i).eDayOfWeek();
					// if the timed task has the same date
					if (sDate.equals(eDate) && sDay.equals(eDay)) {
						tTaskTime = sDate + " " + sDay + " "  + sTime + " ~ " + eTime;
					} else {
						tTaskTime = sDate + " " + sDay + " " + sTime + " ~ " + eDate + " " + eDay + " " + eTime;
					}
				}
				dateTime = "   " + eDate + " " + tasks.get(i).sDayOfWeek() + " " + eTime;
			}
			
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
			Calendar cal = Calendar.getInstance();
			String today = dateFormat.format(cal.getTime());
			if (today.equals(sDate)) {
				urgentTask.add(newUrgent);
			}
			
			String descrip = tasks.get(i).getDescription();
			
			wrappedText.addAll(performWrap(descrip));
			
			taskNum = i + 1;
			taskString = fillSpace(isTimed, wrappedText.get(0), dateTime, tTaskTime, i);
			displayArea.append((taskNum) + ". " + taskString + newline);
			textArea.append((taskNum) + ". " + taskString + newline);
			taskLineNum.add(newUrgent + 1);
			
			if (wrappedText.size() > 1) {
				for(int j = 1; j < wrappedText.size(); j++) {
					displayArea.append(space + space + space + wrappedText.get(j) + newline);
					textArea.append(space + space + space + wrappedText.get(j) + newline);
					taskLineNum.add(newUrgent+1);
				}
			}
			newUrgent++;
			displayArea.append(newline);
			textArea.append(newline);
			taskLineNum.add(0);
			isTimed = false;
		}
		
	}
	
	// hotkeys on the Scheduler
	private class TriggerOnKeyPress implements KeyListener {
		
		public void keyPressed(KeyEvent keyPressed) {
			
			cmdField.requestFocus();
			urgentTask.clear();

			int keyCode = keyPressed.getKeyCode();
			
			
			if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_Q) {			//hotkey to quit Scheduler
		        System.exit(0);
			} else if(keyCode == KeyEvent.VK_ESCAPE) {
				cmdField.setText("");
			} else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_Z) {		// hotkey to undo
				String status = logic.executeCommand(new Command("undo"));
				display(EVERYTHING);
				statusField.setText(status);
			} else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_1) {		// hotkey to show all tasks
				currentView = EVERYTHING;
		        display(EVERYTHING);
				try {
					displayArea.setCaretPosition(displayArea.getLineStartOffset(0));
				} catch (BadLocationException e) {}
			} else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_2) {		// hotkey to show completed tasks
				currentView = COMPLETED;
		        display(COMPLETED);
		        try {
					displayArea.setCaretPosition(displayArea.getLineStartOffset(0));
				} catch (BadLocationException e) {}
			} else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_3) {		// hotkey to show Pending tasks
		        currentView = INCOMPLETED;
		        display(INCOMPLETED);		
		        try {
					displayArea.setCaretPosition(displayArea.getLineStartOffset(0));
				} catch (BadLocationException e) {}
			} else if(keyCode == KeyEvent.VK_UP) {									// hotkey to show previous command
				if (commandHistory.size() > 0 && cmdHistPointer != 0) {
					cmdHistPointer -= 1;
					String input =  commandHistory.get(cmdHistPointer);
					cmdField.setText(input);
					cmdField.selectAll();
				}
			} else if(keyCode == KeyEvent.VK_DOWN) {								// hotkey to show next command
				if (commandHistory.size() > 0 && cmdHistPointer != (commandHistory.size()-1)) {
					cmdHistPointer += 1;
					String input =  commandHistory.get(cmdHistPointer);
					cmdField.setText(input);
					cmdField.selectAll();
				}
			} else if(keyCode == KeyEvent.VK_F1) {									// hotkey to show help
				new help();
			} else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_P) {
				cmdField.setText("add meeting with Ms Chan /by tomorrow 9am");
			} else if(keyCode == KeyEvent.VK_F2) {									// hotkey to show view mode of current view
				enlarge();
				display(currentView);
				try {
					textArea.setCaretPosition(textArea.getLineStartOffset(0));
				} catch (BadLocationException e) {}
				gui.setVisible(false);
			}
		}

		public void keyReleased(KeyEvent e) {}
		public void keyTyped(KeyEvent e) {}
		
	}

	private void highlightChanges(Vector<Integer> changes) {
		for(int i = 0; i < changes.size(); i++) {
			highlightTask(changes.get(i) + 1, CHANGED);
		}
		
	}
	
	private void highlightTask(int taskNum, int type) {
		int lineNumber;
		
		for(int i = 0; i < taskLineNum.size(); i++) {
			if(taskLineNum.get(i) == taskNum) {
				lineNumber = i;
				highlightLine(lineNumber, type);
			}
		}
	}
	
	private void highlightLine(int lineNumber, int type) {
		try
        {
			int startIndex = displayArea.getLineStartOffset(lineNumber);
			int endIndex = displayArea.getLineEndOffset(lineNumber);
			int startIndex2 = textArea.getLineStartOffset(lineNumber);
			int endIndex2 = textArea.getLineEndOffset(lineNumber);

			if (type == CHANGED) {
				painter = new DefaultHighlighter.DefaultHighlightPainter(Color.CYAN);
				displayArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
				textArea.getHighlighter().addHighlight(startIndex2, endIndex2, painter);
            } else if (type == URGENT) {
            	painter = new DefaultHighlighter.DefaultHighlightPainter(Color.ORANGE);
                displayArea.getHighlighter().addHighlight(startIndex, endIndex, painter);
                textArea.getHighlighter().addHighlight(startIndex2, endIndex2, painter);
            }
        } catch(BadLocationException ex) {
        }
		
	}
	
	private class CommandAssist implements DocumentListener{
		@Override
		public void changedUpdate(DocumentEvent e) {
			checkInput();
		}
		@Override
		public void insertUpdate(DocumentEvent e) {
			checkInput();
		}
		@Override
		public void removeUpdate(DocumentEvent e) {
			checkInput();
		}
		private void checkInput() {
			String input = cmdField.getText();
			
			if (input.equals("a")) {
				statusField.setText(" >>> add <task description> /by <date> <time>");
			} else if ( input.equals("d")) {
				statusField.setText(" >>> del <task number>");
			} else if ( input.equals("e")) {
				statusField.setText(" >>> edit <task number> /to <descrip> /by <date> <time>");
			} else if ( input.equals("m")) {
				statusField.setText(" >>> mark <task number>");
			} else if ( input.equals("u")) {
				statusField.setText(" >>> unmark <task number>");
			}
			statusField.selectAll();
		}
		
	}

	// ========================================================
	// ===================== enlarged GUI =====================

		public void enlarge() {
			
			enlargedFrame = new JFrame();
			textArea = new JTextArea();
			eHeading = new JTextField();
			eTextScroll = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
			
			
			EnlargeKeyPress enlargeKeyPress = new EnlargeKeyPress();
			enlargedFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			enlargedFrame.getContentPane().setBackground(new Color(100,150,210, 255));
			
			enlargedFrame.setAlwaysOnTop(true);
			enlargedFrame.setUndecorated(true);
			enlargedFrame.setBackground(new Color(100,150,210, 255));
			enlargedFrame.setShape(new RoundRectangle2D.Double(0,0,900 + extend,600,15,15));
			enlargedFrame.setSize(900 + extend,600);
			
			positionGUI(enlargedFrame);
//			//to position in the center of the screen
//			Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
//			enlargedFrame.setLocation(dim.width/2-enlargedFrame.getSize().width/2, dim.height/2-enlargedFrame.getSize().height/2);
			
			textArea.setBounds(80, 60, 700, 600);
			textArea.setFont(ebodyFont);
			textArea.setBackground(new Color(100,150,210, 255));
			textArea.setForeground(Color.BLACK);
			textArea.setEditable(false);

			eTextScroll.setBorder(null);
			eTextScroll.setBounds(80, 60, 800, 500);
			
			eHeading.setBorder(null);
			eHeading.setBounds(30, 20, 664, 26);
			eHeading.setBackground(new Color(100,150,210, 255));
			eHeading.setFont(eheadingFont);
			eHeading.setForeground(Color.WHITE);
			eHeading.setEditable(false);
			
			enlargedFrame.getContentPane().setLayout(null);
			enlargedFrame.getContentPane().add(eTextScroll);
			enlargedFrame.getContentPane().add(eHeading);
		
			enlargedFrame.setVisible(true);
			
			enlargedFrame.addKeyListener(enlargeKeyPress);
			eHeading.addKeyListener(enlargeKeyPress);
			textArea.addKeyListener(enlargeKeyPress);
			
		}
		

		class EnlargeKeyPress implements KeyListener {

			@Override
			public void keyPressed(KeyEvent keyPressed) {
				//enlargedFrame.dispose();
				int keyCode = keyPressed.getKeyCode();

				if(keyCode == KeyEvent.VK_F2 ) {											// hotkey to exit view mode
					//System.exit(0);
					enlargedFrame.dispose();
					gui.setVisible(true);
				}else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_1) {			// hotkey to change view to all tasks
					currentView = EVERYTHING;
			        display(EVERYTHING);
				}
				else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_2) {			// hotkey to change view to completed tasks
					currentView = COMPLETED;
			        display(COMPLETED);
				}
				else if(keyPressed.isControlDown() && keyCode == KeyEvent.VK_3) {			// hotkey to change view to Pending tasks
			        currentView = INCOMPLETED;
			        display(INCOMPLETED);		        
				}
			}

			@Override
			public void keyReleased(KeyEvent e) {}

			@Override
			public void keyTyped(KeyEvent e) {}
			
		}
		
		
		
		
	// ================== end of enlarged GUI ==================
	// =========================================================
		
	
	//================== for testing ==================
	public String getDisplayContents() {
		return displayArea.getText();
		
	}
	
	public void setCmdField(String cmd) {
		cmdField.setText(cmd);
	}

}
